package servlet;

import service.LoginService;
import serviceimpl.LoginServiceimpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "LoginServlet",urlPatterns = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
               LoginService loginService =new LoginServiceimpl();
               //得到用户名和密码
               String username=request.getParameter("username");
               String password=request.getParameter("password");
              System.out.println(username+password);
               PrintWriter writer = response.getWriter();
        //判断登录
                 if(username!=null && password!=null){
                     //成功跳转到主页面
                    if( loginService.isLogin(username,password))
                        writer.println("ok");
                    //失败跳转到登录页面
                    else
                        writer.println("error");
                 }
        //失败跳转到登录页面
        else
                  writer.println("error");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doGet(request,response);
    }
}
